package com.ruizhong.PIW.controller;

import com.ruizhong.PIW.entity.TUser;
import com.ruizhong.PIW.service.UserService;
import com.ruizhong.PIW.utils.Result;
import com.ruizhong.PIW.utils.ResultCode;
import com.ruizhong.PIW.vo.ListObjectVO;
import com.ruizhong.PIW.vo.PageSearchVO;
import com.ruizhong.PIW.vo.PageVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
@CrossOrigin
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/addUser")
    public Result addUser(@RequestBody TUser user) {
        userService.addUser(user);
        return new Result<>(ResultCode.success, "录入成功", null);
    }

    @PostMapping("/getUserInfoPage")
    public Result getUserInfoPage(@RequestBody PageSearchVO pageSearchVO) {
        PageVO pageVO = userService.getUserInfoPage(pageSearchVO);
        return new Result<>(ResultCode.success, null, pageVO);
    }

    @PostMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody ListObjectVO listObjectVO) {
        userService.removeByIds(listObjectVO.getList());
        return new Result<>(ResultCode.success, "删除成功", null);
    }
}
